<template>
    <div>
        <div class="mui-content">
			<div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a :class="['mui-control-item',item.id==0? 'mui-active':'']"  
                        data-wid="tab-top-subpage-1.html" v-for="item in cates" 
                        :key="item.id"
                        @tap="getPhotoListByCateId(item.id)"
                        >
							{{item.title}}
						</a>
					</div>
				</div>
			</div>
		</div>
        <ul class="photolist">
            <router-link :to="'/home/photoinfo/'+item.id" tag="li" 
            v-for="item in list" 
            :key="item.id">
                <img v-lazy="item.img_url">
                <div class="info">
                    <h1 class="info-title">{{item.title}}</h1>
                    <div class="info-body">{{item.content}}</div>
                </div>
            </router-link>
        </ul>
    </div>
</template>
<script>
import mui from "../../../node_modules/vue-awesome-mui/mui/examples/hello-mui/js/mui.min.js"
//node_modules/vue-awesome-mui/mui/js/mui.js
import {Toast} from 'mint-ui'

export default {
    data(){
        return{
            list:[],
            cates:[]
		}
    },
    created(){
        this.getAtllCategory()
        //默认进入页面，就主动请求，所有图片列表数据
        this.getPhotoListByCateId(0)
    },
    mounted(){
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        },
    methods:{
        getAtllCategory(){
            this.$http.get('http://localhost:3000/classification').then(result=>{
            if(result.body){
                result.body.unshift({title:"全部",id:0})
                this.cates=result.body
            }else{
                Toast('获取失败')
            }
        })
        },
        getPhotoListByCateId(cateId){
            this.$http.get('http://localhost:3000/newslist/?'+cateId).then(result=>{
                if(result.body){
                    this.list=result.body
                }else{
                    Toast('获取失败')
                }
            })
        }
    }
    
}


</script>
<style lang="scss" scoped>
*{
    touch-action:pan-y;
}

.photolist{
    list-style: none;
    padding: 10px;
    margin: 0;
    padding-bottom: 0;
    img{
        width: 100%;
        vertical-align: middle;
    }
    li{
        box-shadow: 0 0 9px #999;
        margin-bottom: 10px;
        background-color: #ccc;
        text-align: center;
        position: relative;
        
    }
    .info{
        position: absolute;
        text-align: center;
        background-color: rgba($color: #000000, $alpha: 0.4);
        bottom: 0;
        color:white;
        max-height: 64px;
        .info-title{
            font-size:14px;
        }
        .info-body{
            font-size:13px;
        }
    }
    img[lazy="loading"] {
    width: 40px;
    height: 300px;
    margin: auto;
    }
}

</style>
